'use strict';
import React from 'react';
import {Button, Form, Popconfirm, Table} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';
import DescGroup from "../../../components/DescriptionGroup";
import ViewTitle from "../../../components/ViewTitle";
import notify from "../../../components/NotificationExtra";
import styles from "../../index.less";
import {ModalView} from "antd-extra";
import ModalAddOrEditProd from "./ModalAddOrEditProd";
import DescriptionGroup from "../../../components/DescriptionGroup";

moment.locale('zh-cn');

@Form.create()
@connect(({user, global, dynamicLabel, sales, store}) => ({...user, ...store, ...sales, ...dynamicLabel, ...global}))
export default class ModalProdDetail extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
  }

  getCols = () => {
    return [
      {
        title: "原料", dataIndex: 'name', key: 'name', render: (value, record) => {
          const {code} = record;
          return this.getProductionElement(code, value);
        }
      },

      {title: '原料形态', key: 'subcategory', dataIndex: "subcategory"},
      {title: '原料规格', key: 'spec', dataIndex: "spec"},
      {title: '原料编码', key: 'number', dataIndex: "number"},
      {title: '原料数量', key: 'materialCount', dataIndex: "materialCount"},
      {title: '单价', key: 'price', dataIndex: "price"},
      {title: '原料含量', key: 'materialContent', dataIndex: "materialContent"},
      {
        title: '成本', key: 'cost', dataIndex: "cost", render: (value, record) => {
        const{price=0,materialCount=0} = record;
        return <div>{price*materialCount}</div>
        }
      }];
  };

  render() {
    const {values, table = 'SalesOrder'} = this.props;
    const model = this.props[`${table}Model`];
    const {materials = [], fileList = []} = values;
    const labels = [];
    console.log('prodds', values);
    _.map(model.prods, (value, key) => {
      const {title, _type} = value;
      if (_type === 'date') {
        const temp = values[key];
        temp ? values[key] = moment(temp).format('YYYY-MM-DD') : undefined;
      }
      title && labels.push({key, label: title});
    });
    return <div>

      <DescriptionGroup
        title={'商品详情'}
        labels={labels}
        values={values}
      ></DescriptionGroup>
      <ViewTitle
        title={'原料列表'}
      >

      </ViewTitle>
      <Table
        className={styles.antTable}
        bordered={true}
        columns={this.getCols()}
        dataSource={materials}
        scroll={{x: true}}
        pagination={true}
      ></Table>
      {this.getPicCard(fileList)}
    </div>;
  }
}
